package com.zjitc.utils;

import com.zjitc.model.Page;

import java.util.List;


/**
 * Create by IntelliJ IDEA
 *
 * @author: lhl
 * @date-Time: 2018/5/18 0018
 * @description:
 */
public class Paging<T> {

    public Page getPage(int pageIndex, int pageCount, List<T> list) {
        Page page = new Page();
        page.setPageIndex(pageIndex);
        page.setPageTotal(pageCount);
        page.setList(list);
        int start = pageIndex - 4;
        if (start < 0) {
            start = 0;
        }
        int end = start + 8;
        if (end > page.getPageTotal()) {
            end = page.getPageTotal();
        }
        int seven = 7;
        while (end - start < seven) {
            if (start > 0) {
                start--;
            }
            if (start == 0) {
                break;
            }
        }
        page.setStart(start);
        page.setEnd(end);
        return page;
    }
}
